﻿using System;
using PSE.Deployment.Engine;
using PSE.Deployment.Engine.Enums;
using PSE.Deployment.Engine.Interfaces;
using PSEComponents.Deployment.Setup.UI;

namespace PSEComponents.Deployment.Setup.Wizard.Steps
{
    public class PSEComponents : BaseStep
    {
        public StepNavigationAction NavigationAction { get; protected set; }
        private ComponentsSelection componentsSelection;

        public PSEComponents(IStepGroup parent)
            : base(parent)
        {
            this.Id = "SinacorComponents";
            this.ErrorBehavior = PSE.Deployment.Engine.Enums.StepErrorBehavior.NotifyParent;
            this.NavigationBehavior = PSE.Deployment.Engine.Enums.StepNavigationBehavior.NextPreviousCancel;

            this.ExecutionFinished += new EventHandler<PSE.Deployment.Engine.CustomEventArgs.ExecutionFinishedEventArgs>(SinacorComponents_ExecutionFinished);
        }

        void SinacorComponents_ExecutionFinished(object sender, PSE.Deployment.Engine.CustomEventArgs.ExecutionFinishedEventArgs e)
        {
            e.NavigationAction = this.NavigationAction;
        }

        public override void Execute()
        {
            componentsSelection = new ComponentsSelection();
            componentsSelection.ShowDialog();
            this.NavigationAction = componentsSelection.NavigationAction.GetValueOrDefault();
        }

        public override void Undo()
        {
            if (componentsSelection != null)
                componentsSelection.Close(false);
        }
    }
}
